package org.southyin.demo04;

import org.southyin.utils.DBUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Date;

public class JDBCDemo01 {
    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            conn = DBUtils.getInstance().getConnection();
            String sql = "select * from emp";
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            while (rs.next()) {
                long id = rs.getLong("id");
                String ename = rs.getString("ename");
                String job = rs.getString("job");
                Date birthday = new Date(rs.getDate("birthday").getTime());
                System.out.println(id + "," + ename + "," + job + "," + birthday);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DBUtils.getInstance().close(rs);
            DBUtils.getInstance().close(ps);
            DBUtils.getInstance().close(conn);
        }
    }
}
